package com.tuanzi.loan.schedule.receipt.monitor.sender;

import com.base.common.log.LogService;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.springframework.stereotype.Service;

@Service
public class DingTalkService {

    public void sendMessage(String url, String content) {
        try {
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost(url);
            httppost.addHeader("Content-Type", "application/json;charset=utf-8");
            String textMsg = String.format("{\"msgtype\": \"text\", \"text\": {\"content\": \"%s\"}}", content);
            StringEntity se = new StringEntity(textMsg, "utf-8");
            httppost.setEntity(se);
            httpclient.execute(httppost);
        } catch (Exception e) {
            LogService.error("钉钉发送发生异常", e);
        }
    }
}
